package com.oasen.learn.usercenter.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oasen.learn.usercenter.dao.UserAuthDao;
import com.oasen.learn.usercenter.dao.UserDao;
import com.oasen.learn.usercenter.entity.UserAuthMeta;
import com.oasen.learn.usercenter.entity.UserMeta;

@Service
@Transactional(readOnly=false,rollbackFor=Exception.class)
public class UserMetaService {
	@Autowired
    private UserDao userMetaDao;
	@Autowired
	private UserAuthDao userAuthDao;

	public void register(UserMeta userMeta,UserAuthMeta	userAuthMeta){
        StandardPasswordEncoder encoder = new StandardPasswordEncoder("53cr3t");
        String enpass = encoder.encode(userMeta.getUpass());
        userMeta.setUpass(enpass);
        userMeta.setEnabled(true);
        userMetaDao.insert(userMeta);
        userAuthMeta.setUname(userMeta.getUname());
        userAuthDao.insert(userAuthMeta);
    }
}

